package org.hot100_1;

import org.leetcode.TreeNode;

public class leetcode39 {
    public boolean isSymmetric(TreeNode root) {
        return  compare(root.left,root.right);
    }

//    public boolean compare(TreeNode left,TreeNode right){
//        if (left==null && right==null){
//            return true;
//        }
//
//        if (left==null && right!=null){
//            return false;
//        }
//
//        if (left!=null && right==null){
//            return false;
//        }
//
//        if (left.val!=right.val){
//            return false;
//        }
//
//        //经过上面的判断，那么当前的left=right，需要对left和right递归调用。
//        boolean outSide = compare(left.left, right.right);
//        boolean inSide =compare(left.right,right.left);
//
//        return outSide && inSide;
//    }

    public boolean compare(TreeNode left,TreeNode right){

        if (left==null && right==null){
            return true;
        }

        if (left==null && right!=null){
            return false;
        }
        if (right==null && left!=null){
            return false;
        }

        if (left.val!=right.val){
            return false;
        }

        boolean inSideIsSame =  compare(left.left,right.right);

        boolean outSideIsSame = compare(left.right,right.left);

        return inSideIsSame && outSideIsSame;

    }
}
